package com.lin.ovc.pomodoro.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.lin.ovc.pomodoro.entity.Plan;
import com.lin.ovc.pomodoro.entity.dto.PlanForm;
import com.lin.ovc.pomodoro.entity.dto.TaskForm;
import com.lin.ovc.pomodoro.mapper.PlanMapper;
import com.lin.ovc.pomodoro.service.PlanService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author lin
 * @since 2024-07-25
 */
@Service
public class PlanServiceImpl extends ServiceImpl<PlanMapper, Plan> implements PlanService {
    @Override
    public boolean save(PlanForm form){
        Plan plan = new Plan();
        BeanUtils.copyProperties(form, plan);
        plan.setUserId(111);
        plan.setCount(0);
        boolean flag = this.save(plan);
        if(flag)return true;
        return false;
    }

    @Override
    public boolean update(TaskForm form) {
        Plan plan = new Plan();
        BeanUtils.copyProperties(form, plan);
        boolean flag = this.updateById(plan);
        if(flag)return true;
        return false;
    }

    @Override
    public List<Plan> list(long id) {
        QueryWrapper wrapper = new QueryWrapper();
        wrapper.eq("user_id",id);
        List<Plan> plans = this.list(wrapper);
        return plans;
    }
}
